package com.c2b.algorithm.newcoder.double_pointer;

/**
 * <a href="https://www.nowcoder.com/practice/e297fdd8e9f543059b0b5f05f3a7f3b2?tpId=295&tqId=658&ru=%2Fpractice%2F75e878df47f24fdc9dc3e400ec6058ca&qru=%2Fta%2Fformat-top101%2Fquestion-ranking&sourceUrl=%2Fexam%2Foj">判断是否为回文字符串</a>
 * <p>给定一个长度为 n 的字符串，请编写一个函数判断该字符串是否回文。如果是回文请返回true，否则返回false。</p>
 * 字符串回文指该字符串正序与其逆序逐字符一致。<br>
 *
 * <p>
 * 数据范围：0 < n ≤1000000<br>
 * 要求：空间复杂度O(1)，时间复杂度O(n)
 * </p>
 *
 * @author c2b
 * @since 2023/3/15 14:45
 */
public class BM0088Judge_S {

    public boolean judge(String str) {
        char[] chars = str.toCharArray();
        int leftIndex = 0;
        int rightIndex = chars.length - 1;
        while (leftIndex < rightIndex) {
            if (chars[leftIndex] != chars[rightIndex]) {
                return false;
            }
            leftIndex++;
            rightIndex--;
        }
        return true;
    }

    public static void main(String[] args) {
        BM0088Judge_S bm0088Judge_s = new BM0088Judge_S();
        System.out.println(bm0088Judge_s.judge("abssba"));
        System.out.println(bm0088Judge_s.judge("ranko"));
        System.out.println(bm0088Judge_s.judge("yamatomaya"));
        System.out.println(bm0088Judge_s.judge("a"));
    }
}
